<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('新增字典项')"/>
    <style type="text/css">
    .ibox-content {padding-bottom:3px !important;}
    .wrapper-content {padding-bottom:5px !important;}
    </style>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <form class="form-horizontal" method="post" th:action="@{/sys/dict/add}" id="dictForm">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="required-sign">*</span>字典项性质：</label>
                            <div class="col-sm-7">
                                <label class="radio-inline i-checks" name="typeOrItem_label"><input type="radio" value="0" name="typeOrItem" id="typeOrItem_type" /> <i></i>字典类别</label>
                                <label class="radio-inline i-checks" name="typeOrItem_label"><input type="radio" value="1" name="typeOrItem" id="typeOrItem_item" checked="checked" /> <i></i>字典元素</label>
                            </div>
                        </div>
                    
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="required-sign">*</span>所属分类：</label>
                            <div class="col-sm-7">
                                <select name="typeId" id="dictTypeDom" class="form-control"></select>
                            </div>
                        </div>
                    
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="required-sign">*</span>字典项名称：</label>
                            <div class="col-sm-7">
                                <input name="txt" type="text" placeholder="字典项名称" class="form-control">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="required-sign">*</span>字典项值：</label>
                            <div class="col-sm-7">
                                <input name="val" id="valDom" type="text" placeholder="字典项值" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-7">
                                <input name="remark" type="text" placeholder="备注" class="form-control" />
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-7">
                                <input class="btn btn-primary" type="submit" value="保存">
                                <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取 消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
    <script th:inline="JavaScript">
    var typeId = '[[${typeId}]]';
    $(document).ready(function () {
    	initTypeSel($("#dictTypeDom"), typeId);
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        $("label[name='typeOrItem_label']").on("click", function () {
            changeType();
        });
        $(".iCheck-helper").on("click", function () {
            changeType();
        });
    });
    
    function changeType() {
    	var ckVal = $("input[name='typeOrItem']:checked").val();
    	if(ckVal == 0) {
    		$("#dictTypeDom").empty();
    		$("#dictTypeDom").attr("disabled",true);
    	} else {
    		initTypeSel($("#dictTypeDom"), typeId);
    		$("#dictTypeDom").attr("disabled",false);
    	}
    }

    Page.validateForm("#dictForm",{
        tips:"确定保存资源信息？",
        debug: false,
        rules: {
            txt: {required: true},
            val: {required: true}
        },
        messages: {
        	txt: {required: "字典项名称不能为空"},
        	val: {required: "字典项名称不能为空"}
        },
        submitSuccess:function(data){
            Dialog.msg("新建成功!",function(){
                parent.reloadTable();
                Dialog.closeFrame(window.name);
            });
        }
    });
</script>

</body>
</html>
